package com.meal.common.model;

import com.meal.common.constants.ResultConstants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 接口返回结构
 * @author Lomis
 *
 */
@Data
@Builder
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {

	private static final long serialVersionUID = 1L;

	private String resultCode = ResultConstants.RESULT_CODE_SUCCESS;	// 结果编码 200:成功 500:失败
	private String resultDesc = ResultConstants.RESULT_DESC_SUCCESS;	// 返回的结果描述
	private T resultData;	// 返回的结果数据

	public  static <T> Result<T> getDefaultFailureResult(T resultData){
		Result<T> result=new Result<>();
		result.setResultCode(ResultConstants.RESULT_CODE_FAILED);
		result.setResultDesc("未知原因，处理失败");
		result.setResultData(resultData);
		return result;
	}

	public  static <T> Result<T> getDefaultSuccessResult(T resultData){
		Result<T> result=new Result<>();
		result.setResultCode(ResultConstants.RESULT_CODE_SUCCESS);
		result.setResultDesc("处理成功");
		result.setResultData(resultData);
		return result;
	}
}
